package com.ruoyi.back.controller

import com.ruoyi.app.common.Data
import com.ruoyi.app.common.PageData
import com.ruoyi.app.common.pageInfo
import com.ruoyi.back.domain.Function
import com.ruoyi.back.service.FunctionService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiImplicitParams
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("system/function")
@Api(tags = ["功能管理"])
class FunctionController {

    @Autowired
    private lateinit var functionService: FunctionService

    @ApiOperation("获取功能分页列表")
    @GetMapping("list")
    fun functionPage(): PageData<Function> = functionService.functionPage().pageInfo()

    @ApiOperation("保存功能菜单")
    @PostMapping("save")
    fun saveFunction(@RequestBody function: Function): Data<Boolean> = functionService.saveFunction(function)

    @ApiOperation("显示隐藏功能")
    @ApiImplicitParams(
        ApiImplicitParam(name = "functionId", value = "功能id 多个使用逗号", type = "path", required = true)
    )
    @GetMapping("show/{functionId}")
    fun showFunction(@PathVariable functionId: Long): Data<Boolean> = functionService.showFunction(functionId)
}